package com.genloong.flycloud.common.bean.VO;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * 接口返回数据基类
 */
@ApiModel(value = "响应结果")
@Data
public class ResultVO<T extends Object> {
    @ApiModelProperty(value = "响应码")
    public int code;
    @ApiModelProperty(value = "提示信息")
    public String msg;
    @ApiModelProperty(value = "响应体 Object 类型")
    public T data;
    //成功码
    public static final int SUCCESS = 20000;
    //失败码
    public static final int FAIL = 40000;
    //错误
    public static final int ERROR = 50000;

    public static <T> ResultVO ResultVOFactory() {
        return new ResultVO<T>();
    }

    /**
     * 成功
     */
    public ResultVO<T> success() {
        this.success("");
        return this;
    }

    public ResultVO<T> success(String msg) {
        this.setCode(SUCCESS);
        this.setMsg(msg);
        return this;
    }

    /**
     * 失败
     */
    public ResultVO<T> fail() {
        this.fail("");
        return this;
    }

    public ResultVO<T> fail(String msg) {
        this.setCode(FAIL);
        this.setMsg(msg);
        return this;
    }

    /**
     * 出错
     */
    public ResultVO<T> error() {
        this.error("");
        return this;
    }

    public ResultVO<T> error(String msg) {
        this.setCode(ERROR);
        this.setMsg(msg);
        return this;
    }
}
